"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _react = require("react");
var utils = _interopRequireWildcard(require("./../utils"));
/**
 * 工具函数
 */
var useHelpers = function useHelpers(options) {
  var _ref = options !== null && options !== void 0 ? options : {},
    _ref$uniqueKey = _ref.uniqueKey,
    uniqueKey = _ref$uniqueKey === void 0 ? 'key' : _ref$uniqueKey,
    _ref$levelKey = _ref.levelKey,
    levelKey = _ref$levelKey === void 0 ? 'level' : _ref$levelKey,
    _ref$childrenKey = _ref.childrenKey,
    childrenKey = _ref$childrenKey === void 0 ? 'children' : _ref$childrenKey,
    _ref$parentKey = _ref.parentKey,
    parentKey = _ref$parentKey === void 0 ? 'parentKey' : _ref$parentKey;
  var forEach = (0, _react.useCallback)(function (treeNodes, callback, opts) {
    return utils.forEach(treeNodes, callback, (0, _objectSpread2.default)({
      childrenKey: childrenKey
    }, opts));
  }, []);
  var map = (0, _react.useCallback)(function (treeNodes, callback) {
    return utils.map(treeNodes, callback, {
      childrenKey: childrenKey
    });
  }, []);
  var filter = (0, _react.useCallback)(function (treeNodes, callback) {
    return utils.filter(treeNodes, callback, {
      childrenKey: childrenKey
    });
  }, []);
  var toArray = (0, _react.useCallback)(function (treeNodes) {
    return utils.toArray(treeNodes, {
      childrenKey: childrenKey
    });
  }, []);
  var toMap = (0, _react.useCallback)(function (treeNodes, options) {
    return utils.toMap(treeNodes, {
      uniqueKey: uniqueKey,
      levelKey: levelKey,
      parentKey: parentKey,
      childrenKey: childrenKey,
      beginingLevel: options === null || options === void 0 ? void 0 : options.beginingLevel
    });
  }, []);
  return {
    forEach: forEach,
    map: map,
    filter: filter,
    toArray: toArray,
    toMap: toMap
  };
};
var _default = useHelpers;
exports.default = _default;